import request from '@/utils/request/req';

// 员工信息接口类型定义
export interface Employee {
  userId: number | string;
  tenantId: null;
  deptId: number;
  userName: string;
  userPlan: null;
  nickName: string;
  userType: null;
  email: string;
  phonenumber: string;
  sex: string;
  avatar: string | null;
  wxAvatar: null;
  password: null;
  status: string;
  loginIp: string;
  loginDate: string;
  remark: string | null;
  createTime: string;
  dept: {
    deptId: number;
    parentId: null;
    parentName: null;
    ancestors: null;
    deptName: string;
    orderNum: null;
    leader: string;
    phone: null;
    email: string;
    status: string;
    createTime: string;
  };
  domainName: null;
  roles: Array<{
    roleId: null;
    roleName: null;
    roleKey: null;
    roleSort: null;
    dataScope: null;
    menuCheckStrictly: null;
    deptCheckStrictly: null;
    status: string;
    remark: string | null;
    createTime: string;
    flag: boolean;
    superAdmin: boolean;
  }>;
  roleIds: null;
  postIds: null;
  roleId: null;
  userGrade: string;
  userBalance: number;
}

// 响应数据接口类型定义
export interface EmployeeListResponse {
  total: number;
  rows: Employee[];
  code: number;
  msg: string;
}

// 查询参数接口类型定义
export interface EmployeeListParams {
  pageNum?: number;
  pageSize?: number;
  userName?: string;
  phonenumber?: string;
  status?: string;
  deptId?: number;
}

// 新增员工参数接口类型定义
export interface AddEmployeeParams {
  deptId: number;
  userName: string;
  nickName: string;
  email: string;
  phonenumber: string;
  sex: string;
  userGrade?: string;
  userBalance?: number;
  remark?: string;
}

// 编辑员工参数接口类型定义
export interface EditEmployeeParams {
  userId: number | string;
  deptId: number;
  userName: string;
  nickName: string;
  email: string;
  phonenumber: string;
  sex: string;
  userGrade?: string;
  userBalance?: number;
  remark?: string;
}

/**
 * 查询员工列表
 * @param params 查询参数
 * @returns Promise<EmployeeListResponse>
 */
export function getEmployeeList(params: EmployeeListParams) {
  return request<EmployeeListResponse>({
    url: '/enterprise/empList',
    method: 'get',
    params
  });
}

/**
 * 新增员工
 * @param data 员工信息
 * @returns Promise<any>
 */
export function addEmployee(data: AddEmployeeParams) {
  return request({
    url: '/enterprise/addEmp',
    method: 'post',
    data
  });
}

/**
 * 编辑员工
 * @param data 员工信息
 * @returns Promise<any>
 */
export function editEmployee(data: EditEmployeeParams) {
  return request({
    url: '/enterprise/editEmp',
    method: 'post',
    data
  });
}

/**
 * 删除员工
 * @param userId 员工ID
 * @returns Promise<any>
 */
export function deleteEmployee(userId: number | string) {
  return request({
    url: `/enterprise/deleteEmp/${userId}`,
    method: 'post'
  });
}
